<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>ui.TabPanel Test Suite</title>
<link type="text/css" rel="stylesheet" href="../../../js/tinymce/skins/lightgray/skin.min.css" />
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<link rel="stylesheet" href="css/ui-overrides.css" type="text/css" />
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css" type="text/css" />
<script src="http://code.jquery.com/qunit/qunit-git.js"></script>
<script src="../../js/qunit/reporter.js"></script>
<script src="../../js/utils.js"></script>
<script src="../../js/tinymce_loader.js"></script>
<script type="text/javascript">
var panel;
QUnit.config.autostart = false;
QUnit.config.reorder = false;

module("ui.TabPanel", {
	setup: function() {
		document.getElementById('view').innerHTML = '';
	},

	teardown: function() {
		//document.getElementById('view').innerHTML = '';
	}
});

window.onload = function() {
	QUnit.start();
};

function createTabPanel(settings) {
	return tinymce.ui.Factory.create(tinymce.extend({
		type: 'tabpanel',
		items: [
			{title: 'a', type: 'spacer', classes: 'red'},
			{title: 'b', type: 'spacer', classes: 'green'},
			{title: 'c', type: 'spacer', classes: 'blue'}
		]
	}, settings)).renderTo(document.getElementById('view')).reflow();
}

test("panel width: 100, height: 100", function() {
	panel = createTabPanel({
		width: 100,
		height: 100,
		layout: 'fit'
	});

	deepEqual(rect(panel), [0, 0, 100, 100]);
	nearlyEqualRects(rect(panel.items()[0]), [0, 31, 100, 69], 4);
});

test("panel width: 100, height: 100, border: 1", function() {
	panel = createTabPanel({
		width: 100,
		height: 100,
		border: 1,
		layout: 'fit'
	});

	deepEqual(rect(panel), [0, 0, 100, 100]);
	nearlyEqualRects(rect(panel.items()[0]), [0, 31, 100, 69], 4);
});

test("panel width: 100, height: 100, activeTab: 1", function() {
	panel = createTabPanel({
		width: 100,
		height: 100,
		activeTab: 1,
		layout: 'fit'
	});

	deepEqual(rect(panel), [0, 0, 100, 100]);
	nearlyEqualRects(rect(panel.items()[1]), [0, 31, 100, 69], 4);
});

test("panel width: auto, height: auto, mixed sized widgets", function() {
	panel = createTabPanel({
		items: [
			{title: 'a', type: 'spacer', classes: 'red', style: 'width: 100px; height: 100px'},
			{title: 'b', type: 'spacer', classes: 'green', style: 'width: 70px; height: 70px'},
			{title: 'c', type: 'spacer', classes: 'blue', style: 'width: 120px; height: 120px'}
		]
	});

	nearlyEqualRects(rect(panel), [0, 0, 120, 151], 4);
	nearlyEqualRects(rect(panel.items()[0]), [0, 31, 120, 120], 4);

	panel.activateTab(1);
	nearlyEqualRects(rect(panel.items()[1]), [0, 31, 120, 120], 4);

	panel.activateTab(2);
	nearlyEqualRects(rect(panel.items()[2]), [0, 31, 120, 120], 4);
});

test("panel width: auto, height: auto, mixed sized containers", function() {
	panel = createTabPanel({
		items: [
			{
				title: 'a',
				type: 'panel',
				layout: 'flex',
				align: 'stretch',
				items: {
					type: 'spacer',
					classes: 'red',
					flex: 1,
					minWidth: 100,
					minHeight: 100
				}
			},

			{
				title: 'b',
				type: 'panel',
				layout: 'flex',
				align: 'stretch',
				items: {
					type: 'spacer',
					flex: 1,
					classes: 'green',
					minWidth: 70,
					minHeight: 70
				}
			},

			{
				title: 'c',
				type: 'panel',
				layout: 'flex',
				align: 'stretch',
				items: {
					type: 'spacer',
					classes: 'blue',
					flex: 1,
					minWidth: 120,
					minHeight: 120
				}
			}
		]
	});

	nearlyEqualRects(rect(panel), [0, 0, 120, 151], 4);
	nearlyEqualRects(rect(panel.items()[0]), [0, 31, 120, 120], 4);

	panel.activateTab(1);
	nearlyEqualRects(rect(panel.items()[1]), [0, 31, 120, 120], 4);

	panel.activateTab(2);
	nearlyEqualRects(rect(panel.items()[2]), [0, 31, 120, 120], 4);
});
</script>
</head>
<body>
	<h1 id="qunit-header">ui.TabPanel Test Suite</h1>
	<h2 id="qunit-banner"></h2>
	<h2 id="qunit-userAgent"></h2>
	<ol id="qunit-tests">
	</ol>
	<div id="view" style="position: absolute; right: 0; top: 0"></div>
</body>
</html>
